package org.elip.teststatistics.client.ui;

import org.elip.teststatistics.client.LogsServiceAsync;
import org.elip.teststatistics.client.ProductServiceAsync;
import org.elip.teststatistics.client.SuitesServiceAsync;
import org.elip.teststatistics.client.Test_Statistics;
import org.elip.teststatistics.client.TestsServiceAsync;

import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout.VBoxLayoutAlign;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;

public class MainView extends LayoutContainer {
	
	private LogsServiceAsync _logsService;
	private ProductServiceAsync _productService;
	private SuitesServiceAsync _suitesService;
	@SuppressWarnings("unused")
	private TestsServiceAsync _testsService;
	
	private TestInformationPanel _testInformationPanel;
	private TestLogsPanel _testLogsPanel;
	private TestStatisticsPanel _testStatisticsPanel;
	
	public MainView(Test_Statistics testSatistics, LogsServiceAsync logsService, ProductServiceAsync productService,
			SuitesServiceAsync suitesService, TestsServiceAsync testsService) {
		
		this._logsService = logsService;
		this._productService = productService;
		this._suitesService = suitesService;
		this._testsService = testsService;
		
		this._testStatisticsPanel = new TestStatisticsPanel();
		this._testLogsPanel = new TestLogsPanel(_testStatisticsPanel);
		this._testInformationPanel = new TestInformationPanel(_testLogsPanel, _testStatisticsPanel, _logsService, _productService, _suitesService, testsService);
		
		Window.addResizeHandler(new ResizeHandler() {
			
			@Override
			public void onResize(ResizeEvent event) {
				
				int newHeight = event.getHeight();
				int newWidth = event.getWidth();
				
				int n = newHeight - 2 * 44;
				
				// resize elements width
				_testInformationPanel.setWidth(newWidth);
				_testStatisticsPanel.setWidth(newWidth);
				_testLogsPanel.setWidth(newWidth);
				_testLogsPanel.setTabPanelWidth(newWidth);
				
				// resize elemens height
				_testInformationPanel.setHeight(44);
				_testLogsPanel.setHeight(n);
				_testStatisticsPanel.setHeight(44);	
			}
		});
	}
	
	@Override
	protected void onRender(Element parent, int pos) {
		super.onRender(parent, pos);
		
		VBoxLayout layout = new VBoxLayout();
		layout.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);
		
		setLayout(layout);
		
		add(_testInformationPanel);
		add(_testLogsPanel);;
		add(_testStatisticsPanel);
	}
}
